package work.xkong.controller;


import io.jsonwebtoken.Claims;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;
import work.xkong.common.ResponseRest;
import work.xkong.service.ICourseService;
import work.xkong.utils.TokenUtils;
import work.xkong.vo.inputvo.CourseSelectInputVo;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author NuanYang
 * @since 2022-11-21
 */
@RestController
@RequestMapping("/course")
public class CourseController {
    @Autowired
    private ICourseService iCourseService;

    @GetMapping("/getSelectCourse")
    public ResponseRest getSelectCourse(HttpServletRequest request, CourseSelectInputVo inputVo) {
        String jwt = request.getHeader("Authorization");
        String studentId = (String) TokenUtils.getParseToken(jwt).get(Claims.ID);

        inputVo.setId(Integer.parseInt(studentId));

        return iCourseService.getSelectCourse(inputVo);
    }

    @GetMapping("/getStudentCourse")
    public ResponseRest getStudentCourse(HttpServletRequest request, CourseSelectInputVo inputVo) {
        String jwt = request.getHeader("Authorization");
        String studentId = (String) TokenUtils.getParseToken(jwt).get(Claims.ID);

        inputVo.setId(Integer.parseInt(studentId));

        return iCourseService.getStudentCourse(inputVo);
    }

    @GetMapping("/getTeacherCourse")
    public ResponseRest getTeacherCourse(HttpServletRequest request, CourseSelectInputVo inputVo) {
        String jwt = request.getHeader("Authorization");
        String teacherId = (String) TokenUtils.getParseToken(jwt).get(Claims.ID);

        inputVo.setId(Integer.parseInt(teacherId));

        return iCourseService.getTeacherCourses(inputVo);
    }

    @GetMapping("/getStudentScore")
    public ResponseRest getStudentScore(HttpServletRequest request, CourseSelectInputVo inputVo) {
        String jwt = request.getHeader("Authorization");
        String studentId = (String) TokenUtils.getParseToken(jwt).get(Claims.ID);

        inputVo.setId(Integer.parseInt(studentId));

        return iCourseService.getStudentScoreCourse(inputVo);
    }

    @GetMapping("/getCourseTable")
    public ResponseRest getCourseTable(HttpServletRequest request){
        String jwt = request.getHeader("Authorization");
        String studentId = (String) TokenUtils.getParseToken(jwt).get(Claims.ID);

        return iCourseService.getCourseTime(studentId);
    }

    @GetMapping("/getCourseTeacherTable")
    public ResponseRest getCourseTeacherTable(HttpServletRequest request){
        String jwt = request.getHeader("Authorization");
        String teacherId = (String) TokenUtils.getParseToken(jwt).get(Claims.ID);

        return iCourseService.getTeacherCourseTime(teacherId);
    }

    @GetMapping("/getTeacherClass")
    public ResponseRest getTeacherClass(HttpServletRequest request,CourseSelectInputVo inputVo) {
        String jwt = request.getHeader("Authorization");
        String teacherId = (String) TokenUtils.getParseToken(jwt).get(Claims.ID);

        inputVo.setId(Integer.parseInt(teacherId));

        return iCourseService.getTeacherClassCourses(inputVo);
    }
}
